package com.juc.future;

import java.net.HttpCookie;
import java.util.concurrent.*;

/**
 * @Author Zan
 * @Create 2024/5/6 20:44
 * @ClassName : CompletableFutureBuildDemo
 * @Description : TODO 请用一句话描述该类的功能
 */
public class CompletableFutureBuildDemo {
    public static void main(String[] args) throws Exception {
        // new CompletableFuture对象不推荐，使用内部的静态方法进行创建对象
//        CompletableFuture completableFuture = new CompletableFuture();

        ExecutorService threadPool = Executors.newFixedThreadPool(3);

        /*CompletableFuture<Void> completableFuture = CompletableFuture.runAsync(() -> {
            System.out.println(Thread.currentThread().getName());
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }, threadPool);
        System.out.println(completableFuture.get()); // null*/

        CompletableFuture<String> completableFuture = CompletableFuture.supplyAsync(() -> {
            System.out.println(Thread.currentThread().getName());
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            return "Hello SupplyAsync";
        }, threadPool);
        System.out.println(completableFuture.get());

        threadPool.shutdown();


    }
}
